from math import ceil

def paginate_queryset(queryset, page, size):
    """分页处理"""
    # 计算总数
    total = queryset.count()
    
    # 计算总页数
    pages = ceil(total / size) if size > 0 else 0
    
    # 获取当前页数据
    start = (page - 1) * size
    end = start + size
    items = list(queryset[start:end])
    
    return {
        'items': items,
        'total': total,
        'page': page,
        'size': size,
        'pages': pages
    } 